<%@ taglib prefix="page" uri="http://com.qipay/pagelib" %>
<%@ page language="java" import="com.qipay.baas.model.ActionDoc" contentType="text/html;charset=utf-8" %>
<%@ page import="com.qipay.baas.model.ActionDocDetail" %>
<%@ page import="java.util.List" %>
<!doctype html>
<html>
<head>
    <jsp:include page="head.jsp"></jsp:include>
</head>
<body class="devpreview hold-transition skin-blue sidebar-mini">
<div class="wrapper">
    <jsp:include page="nav.jsp"></jsp:include>
    <jsp:include page="left.jsp"></jsp:include>
    <!-- Content Wrapper. Contains page content -->
    <div class="content-wrapper">
        <!-- Main content -->
        <% ActionDocDetail cpChannel = (ActionDocDetail) request.getAttribute("detail");
            List<ActionDoc> cates = (List<ActionDoc>) request.getAttribute("lst");
            boolean isAdd = String.valueOf(request.getAttribute("isadd")).equals("1");

        %>
        <section class="content">
            <div class="row">
                <div class="col-xs-12">
                    <div class="box box-info">
                        <div class="box-header with-border">
                            <h3 class="box-title">编辑支付接口文档</h3>
                        </div>
                        <!-- /.box-header -->
                        <!-- form start -->
                        <form class="form-horizontal" action="save" method="POST" id="doc-vld-msg">
                            <input type="hidden" name="id" value="<%= isAdd?"":String.valueOf(cpChannel.getId())%>">
                            <input type="hidden" name="docId" value="<%= request.getParameter("did")%>">
                            <div class="box-body" id="dvContent">
                                <div class="form-group">
                                    <label for="txttitle" class="col-sm-2 control-label">标题：</label>
                                    <div class="col-sm-10">
                                        <input type="text" class="form-control" id="txttitle" name="title" mush="1"
                                               value="<%= isAdd?"":cpChannel.getTitle()%>" placeholder="标题">

                                    </div>
                                </div>
                                <div class="form-group">
                                    <label for="ddltype" class="col-sm-2 control-label">接口类别：</label>
                                    <div class="col-sm-10">
                                        <select id="ddltype" name="pid">
                                            <% for (ActionDoc doc : cates
                                                    ) {%>
                                            <option value="<%=doc.getId()%>"><%= doc.getTitle()%>
                                            </option>
                                            <%}%>
                                        </select>
                                    </div>
                                    <input type="hidden" name="parntCateName" id="hdparntCateName"
                                           value="<%= isAdd?"":cpChannel.getParntCateName()%>">
                                </div>

                                <div class="form-group">
                                    <label for="txtinfo" class="col-sm-2 control-label">内容：</label>
                                    <div class="col-sm-10">
                                        <span class="help-block">请用makedown格式</span>
                                        <textarea class="form-control" id="txtinfo" name="info" mush="1"
                                                  rows="30"
                                                  placeholder="内容"><%= isAdd ? "" : cpChannel.getInfo()%>
                                        </textarea>
                                    </div>
                                </div>
                            </div>
                            <!-- /.box-body -->
                            <div class="box-footer">
                                <button type="button" class="btn btn-default" onclick="window.history.back()">返回
                                </button>
                                <button type="button" class="button back-green pull-right" id="btnSearch">确 定</button>
                            </div>
                            <!-- /.box-footer -->
                        </form>
                    </div>
                    <!-- /.box -->
                </div>
                <!-- /.col -->
            </div>
            <!-- /.row -->
        </section>
        <!-- /.content -->
    </div>
    <!-- /.content-wrapper -->
    <%--<jsp:include page="foot.jsp"></jsp:include>--%>
</div>
<script src="<%= request.getAttribute("StaticHost") %>/js/fastclick.js"></script>
<script src="<%= request.getAttribute("StaticHost") %>/js/adminlte.min.js"></script>
<script>
    $(function () {
        var currentType = '<%= request.getAttribute("isadd")%>',
            channelState = parseInt("<%= cpChannel !=null&&cpChannel.getPid()!=null?cpChannel.getPid():0%>", 10);
        var isHaveCates = "<%= cates!=null&&cates.size()>0?"1":"7"%>";
        if (isHaveCates == "7") {
            alert("添加文档前，请先添加接口文档类别。");
            window.location.href = "${pageContext.request.contextPath}/doc/add?t=2";
            return;
        }
        if (currentType == "1") {
            channelState = "<%= cates!=null&&cates.size()>0?cates.get(0).getId():0%>";
            $("#ddltype").val(channelState);
            $('#hdparntCateName').val("<%= cates!=null&&cates.size()>0?cates.get(0).getTitle():""%>");
        }
        else {
            $("#ddltype").val(channelState);

        }
        $("#ddltype").change(function () {
            $('#hdparntCateName').val($('#ddltype').find("option:selected").text());
        });
        $("#btnSearch").on("click", function () {
            var isGo = checkInputMust("dvContent");
            if(isGo) {
                $("#doc-vld-msg")[0].submit();
            }
        });

    });
</script>
</body>
</html>

